home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 3 / Light ROM 3 - Disc 2.iso / programs / amiga / imagefx / imagekit / imagekit.lha / ImageFX_SDK / sas / examples / xdraw / blur.c < prev    next >
C/C++ Source or Header  |  1995-02-15  |  6KB  |  272 lines

  1. /*
  2.  * A Blur Enhanced Drawing Mode for ImageFX 2.0
  3.  *
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <scan/modall.h>
  8. #include <scan/drawinfo.h>
  9.  
  10. /**********************************************************************\
  11.  
  12.                                 Library Vectors
  13.  
  14. \**********************************************************************/
  15.  
  16. /*
  17.  * XDM_Attr:
  18.  *
  19.  * Return to ImageFX some information about the Drawing Mode (eg.
  20.  * whether Options are needed, whether we work on greyscale or
  21.  * color, etc.).  Called when ImageFX first scans the drawing
  22.  * mode directory.
  23.  *
  24.  */
  25. ULONG __saveds __asm XDM_Attr (register __a0 struct XDrawAttr *da)
  26. {
  27.    da->Flags      = XDMF_NoPen;
  28.    da->Priority   = 118;
  29.    da->HorizOffs  = 1;
  30.    da->VertOffs   = 1;
  31.    return(0);
  32. }
  33.  
  34. /*
  35.  * XDM_Init:
  36.  *
  37.  * Initialize the drawing mode.
  38.  *
  39.  */
  40. int __saveds __asm XDM_Init (void)
  41. {
  42.    return(1);
  43. }
  44.  
  45. /*
  46.  * XDM_Cleanup:
  47.  *
  48.  * Cleanup the drawing mode.
  49.  *
  50.  */
  51. void __saveds __asm XDM_Cleanup (void)
  52. {
  53. }
  54.  
  55. /*
  56.  * XDM_Begin:
  57.  *
  58.  * Prepare before a pixel affecting operation.
  59.  *
  60.  */
  61. int __saveds __asm XDM_Begin (register __a0 struct IDrawInfo *di)
  62. {
  63.    return(1);
  64. }
  65.  
  66. /*
  67.  * XDM_End:
  68.  *
  69.  * Cleanup after a pixel affecting operation.
  70.  *
  71.  */
  72. void __saveds __asm XDM_End (register __a0 struct IDrawInfo *di)
  73. {
  74. }
  75.  
  76. /*
  77.  * XDM_Affect:
  78.  *
  79.  * Affect a block of pixels.  We may also affect some of the
  80.  * parameters of the IDrawInfo structure, such as the X & Y
  81.  * location of the block of pixels.
  82.  *
  83.  */
  84. void __saveds __asm XDM_Affect (register __a0 struct IDrawInfo *di)
  85. {
  86. #ifdef USE_BUFFERS
  87.  
  88.    int i, j, y;
  89.    UBYTE *ored, *ogrn, *oblu;
  90.    UBYTE *ired, *igrn, *iblu;
  91.  
  92.    ored = di->OutR;
  93.    ogrn = di->OutG;
  94.    oblu = di->OutB;
  95.  
  96.    for (y = 1, j = 0; j < di->Height; y++, j++)
  97.    {
  98.       GetBufLines(di->BBuf, &ired, &igrn, &iblu, y-1, 3);
  99.       GetBufLine(di->BOut, &ored, &ogrn, &oblu, j);
  100.       ired += di->BufW + 1;
  101.       igrn += di->BufW + 1;
  102.       iblu += di->BufW + 1;
  103.  
  104.       for (i = 0; i < di->Width; i++) {
  105.  
  106.          *ored = ( *(ired - di->BufW) +
  107.                    *(ired -        1) +
  108.                    *(ired +        1) +
  109.                    *(ired + di->BufW) +
  110.                    *(ired) * 4        ) / 8;
  111.          *ogrn = ( *(igrn - di->BufW) +
  112.                    *(igrn -        1) +
  113.                    *(igrn +        1) +
  114.                    *(igrn + di->BufW) +
  115.                    *(igrn) * 4        ) / 8;
  116.          *oblu = ( *(iblu - di->BufW) +
  117.                    *(iblu -        1) +
  118.                    *(iblu +        1) +
  119.                    *(iblu + di->BufW) +
  120.                    *(iblu) * 4        ) / 8;
  121.  
  122.          ored++; ogrn++; oblu++;
  123.          ired++; igrn++; iblu++;
  124.       }
  125.  
  126.       PutBufLine(di->BOut);
  127.    }
  128.  
  129. #else
  130.  
  131.    int i, j;
  132.    UBYTE *ored, *ogrn, *oblu;
  133.    UBYTE *ired, *igrn, *iblu;
  134.  
  135.    ored = di->OutR;
  136.    ogrn = di->OutG;
  137.    oblu = di->OutB;
  138.  
  139.    for (j = 0; j < di->Height; j++) {
  140.       ired = di->BufR + (j * di->BufW);
  141.       igrn = di->BufG + (j * di->BufW);
  142.       iblu = di->BufB + (j * di->BufW);
  143.       for (i = 0; i < di->Width; i++) {
  144.  
  145.          *ored = ( *(ired - di->BufW) +
  146.                    *(ired -        1) +
  147.                    *(ired +        1) +
  148.                    *(ired + di->BufW) +
  149.                    *(ired) * 4        ) / 8;
  150.          *ogrn = ( *(igrn - di->BufW) +
  151.                    *(igrn -        1) +
  152.                    *(igrn +        1) +
  153.                    *(igrn + di->BufW) +
  154.                    *(igrn) * 4        ) / 8;
  155.          *oblu = ( *(iblu - di->BufW) +
  156.                    *(iblu -        1) +
  157.                    *(iblu +        1) +
  158.                    *(iblu + di->BufW) +
  159.                    *(iblu) * 4        ) / 8;
  160.  
  161.          ored++; ogrn++; oblu++;
  162.          ired++; igrn++; iblu++;
  163.       }
  164.    }
  165.  
  166. #endif
  167. }
  168.  
  169. /*
  170.  * XDM_Options:
  171.  *
  172.  * Present a window to the user allowing him to adjust drawing mode
  173.  * options.  Arguments may optionally be passed from an Arexx command.
  174.  * This function will only be called if the flag XDMF_AreOptions is
  175.  * returned from XDM_Attr().
  176.  *
  177.  */
  178. int __saveds __asm XDM_Options (register __a0 LONG *args)
  179. {
  180.    return(0);
  181. }
  182.  
  183. /*
  184.  * XDM_LoadPrefs:
  185.  *
  186.  * Set preferences according to information loaded from disk.
  187.  *
  188.  */
  189. int __saveds __asm XDM_LoadPrefs (register __a0 void *prefs)
  190. {
  191.    return(1);
  192. }
  193.  
  194. /*
  195.  * XDM_SavePrefs:
  196.  *
  197.  * Request preferences settings that are about to be saved to disk.
  198.  *
  199.  */
  200. int __saveds __asm XDM_SavePrefs (register __a0 void *prefs)
  201. {
  202.    return(1);
  203. }
  204.  
  205.  
  206. /**********************************************************************\
  207.  
  208.                          Library Initialization Stuff
  209.  
  210. \**********************************************************************/
  211.  
  212. /*
  213.  * This is the table of all the functions that can be called in this
  214.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  215.  * for system use and MUST be specified in the order shown.  The actual
  216.  * functions are in the standard module startup code.
  217.  */
  218. ULONG FuncTable[] = {
  219.    /* These four MUST be present in this order */
  220.    (ULONG) LibOpen,
  221.    (ULONG) LibClose,
  222.    (ULONG) LibExpunge,
  223.    (ULONG) LibNull,
  224.  
  225.    /* Specific to the module */
  226.    (ULONG) XDM_Attr,
  227.    (ULONG) XDM_Begin,
  228.    (ULONG) XDM_End,
  229.    (ULONG) XDM_Affect,
  230.    (ULONG) XDM_Options,
  231.    (ULONG) XDM_LoadPrefs,
  232.    (ULONG) XDM_SavePrefs,
  233.    (ULONG) 0,
  234.    (ULONG) 0,
  235.    (ULONG) XDM_Init,
  236.    (ULONG) XDM_Cleanup,
  237.  
  238.    /* End with -1L */
  239.    (ULONG) -1L
  240. };
  241.  
  242. /*
  243.  * These are used by the standard module startup code.
  244.  * LibraryName is the name of the library, and LibraryID is a short
  245.  * description of the library.  Both of these are largely irrelavent,
  246.  * but they are included just for completeness.
  247.  */
  248. UBYTE LibraryID[]    = "$VER: Blur Extended Drawing Mode 2.0.6 (15.2.95)";
  249. UBYTE LibraryType    = NT_XDRAWMODE;
  250.  
  251. /*
  252.  * This is called by the standard module startup code when Image Scan
  253.  * first opens the module.  Here we should fill in the NumGads,
  254.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  255.  * structure if necessary.
  256.  */
  257. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  258. {
  259.    return(TRUE);
  260. }
  261.  
  262. /*
  263.  * This is called by the standard module startup code when Image Scan
  264.  * closes the module.  It should cleanup anything allocated or obtained
  265.  * in the UserOpen() function.
  266.  */
  267. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  268. {
  269.    return(TRUE);
  270. }
  271.  
  272.